package org.mobile.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mobile.logic.OrderLogic;

/**
 * Servlet implementation class UpdateOrderStatus
 */
@WebServlet(name = "updateOrderStatus", urlPatterns = { "/updateOrderStatus" })
public class UpdateOrderStatus extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public UpdateOrderStatus() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String status= request.getParameter("status");
		int orderID= Integer.parseInt(request.getParameter("orderID"));
		if(!OrderLogic.getInstance().changeStatus(status, orderID)){
			request.setAttribute("error", "Błąd aktualizacji statusu zamówienia!");
			request.getRequestDispatcher("errPage.jsp").forward(request, response);
		}
		else{
			request.setAttribute("message", "Zaktualizowano status zamówienia");
			request.getRequestDispatcher("index.jsp").forward(request, response);
		}
		
	}
		
	
}
